﻿using System;
using System.Collections.Generic;

namespace timetable
{
    [Serializable]
    public class GroupList
    {
        public int Count { get; private set; }
        public int Length { get { return List.Count; }private set{}}
        public List<Group> List { get; private set; }
        public List<Student> StuList { get; set; }
        public HashSet<string> CourseSet ;
        public bool isResult;

        public GroupList(bool isResult = false)
        {
            CourseSet = new HashSet<string>();
            List = new List<Group>();
            this.isResult = isResult;
            StuList = new List<Student>();
        }

        public GroupList(GroupList list)
        {
            Count = list.Count;
            Length = list.Length;

            CourseSet = new HashSet<string>(list.CourseSet);
            isResult = list.isResult;

            List = new List<Group>();
            Group newGroup;
            foreach (Group @group in list.List)
            {
               newGroup = new Group(group);
               List.Add(newGroup);
            }

            StuList = new List<Student>();
            Student newStudent;
            foreach (Student student in list.StuList)
            {
                newStudent = new Student(student);
                StuList.Add(newStudent);
            }
            
        }

        
        /// <summary>
        /// 将分组归入班级，同时修改课程名称，确定是不是单独上还是一起上
        /// </summary>
        /// <param name="g"></param>
        /// <param name="index">默认值3表示当前初始化，尚未赋值</param>
        public void Add(Group g,int index = 3)
        {
            List.Add(g); 
            Count += g.count;

            
            if (isResult)
            {
                foreach (KeyValuePair<string, string> keyValuePair in g.Common)
                {
                    string oldName = keyValuePair.Key;
                    string newName = keyValuePair.Key + index + keyValuePair.Value + 0;
                    g.Curriculum.changeCourseName(oldName,newName,false);
                }
                foreach (KeyValuePair<string, string> keyValuePair in g.Special)
                {
                    string oldName = keyValuePair.Key;
                    string newName = keyValuePair.Key + index+ keyValuePair.Value + 1;
                    g.Curriculum.changeCourseName(oldName, newName,true);
                }
                CourseSet.UnionWith(g.Curriculum.CourseSet);
            }

        }
    }

}
